package com.hl233.framework.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 张振强15065206763
 * @create 2024-09-07
 */
@RestController
@RequestMapping("/testMQ")
public class SendRabbitMQController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping(value = "/sendmessage/{val}")
    public String sendMessage(@PathVariable("val") String val){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String test = "当前时间："+dateFormat.format(new Date());
        rabbitTemplate.convertAndSend("helloMQ", val+"sssd"+test);
        return "消息已经发送到helloMQ消息列队中";
    }
}
